﻿package mortal.game.view.guide
{
    import Message.Public.*;
    import com.gengine.core.frame.*;
    import mortal.game.cache.*;
    import mortal.game.mvc.*;
    import mortal.game.net.rmi.*;
    import mortal.game.scene3D.ai.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.view.common.guide.*;
    import mortal.game.view.common.guide.data.*;
    import mortal.game.view.task.data.*;

    public class GuideAutoDoTask extends Object
    {
        private var _timer:FrameTimer;
        private var _lastTime:int = 0;
        public static var isNotAutoDoTask:Boolean = false;

        public function GuideAutoDoTask()
        {
            return;
        }// end function

        public function work() : void
        {
            if (this._timer == null)
            {
                this._timer = new FrameTimer(5);
                this._timer.addListener(TimerType.ENTERFRAME, this.onEnterFrameHandler);
            }
            this._timer.start();
            return;
        }// end function

        private function onEnterFrameHandler(param1 = null) : void
        {
            var _loc_6:TaskInfo = null;
            if (isNotAutoDoTask || AutoGuideCache.isNotAutoAI)
            {
                return;
            }
            if (GameRMI.instance.isConnected == false)
            {
                return;
            }
            if (GameController.guide.isFirstTimeInGame)
            {
                return;
            }
            if (AIManager.isWorking)
            {
                return;
            }
            if (RolePlayer.instance.entityInfo == null || RolePlayer.instance.entityInfo.isDead)
            {
                return;
            }
            if (Cache.instance.task.isDrama)
            {
                return;
            }
            if (AutoGuideController.isGuiding)
            {
                return;
            }
            var _loc_2:* = FrameManager.flashFrame.getTime();
            if (_loc_2 - this._lastTime < 1000)
            {
                return;
            }
            var _loc_3:int = 10000;
            var _loc_4:* = Cache.instance.role.roleInfo.level;
            if (_loc_4 <= 25)
            {
                _loc_3 = 5000;
            }
            var _loc_5:* = Math.min(_loc_2 - AIManager.endTime, _loc_2 - this._lastTime);
            if (_loc_5 >= _loc_3)
            {
                _loc_6 = Cache.instance.task.getNextAutoPathTask();
                if (_loc_6 != null && _loc_6.stask.group == ETaskGroup._ETaskGroupMain && !_loc_6.isCanNotEnd())
                {
                    if (GameController.guide.resumeToTask())
                    {
                        this._lastTime = _loc_2;
                        return;
                    }
                }
            }
            if (_loc_5 >= 20000)
            {
                _loc_6 = Cache.instance.task.getTaskInfoByGroup(ETaskGroup._ETaskGroupMain);
                if (_loc_6 != null && _loc_6.isCanNotEnd())
                {
                    _loc_6 = Cache.instance.task.getTaskInfoByGroup(ETaskGroup._ETaskGroupLoop);
                    if (_loc_6 != null)
                    {
                        TaskUtil.linkTask(_loc_6);
                        this._lastTime = _loc_2;
                    }
                }
            }
            return;
        }// end function

        public function stop() : void
        {
            if (this._timer != null)
            {
                this._timer.stop();
            }
            this._timer = null;
            return;
        }// end function

    }
}
